<?php defined('_VALID_MOS') or die('Direct Access to this location is not allowed.');

/*
 * Copyright Copyright (C) 2007 Alain Georgette. All rights reserved.
 * Copyright Copyright (C) 2006 Frantisek Hliva. All rights reserved.
 * License http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
 *
 * !JoomlaComment is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * !JoomlaComment is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 * MA  02110-1301, USA.
 */

// check access permissions (only superadmins & admins)
if ( !( $acl->acl_check('administration', 'config', 'users', $my->usertype) ) 
	||  $acl->acl_check('administration', 'edit', 'users', $my->usertype, 'components', 'com_comment') ) {
	mosRedirect( 'index2.php', _NOT_AUTH );
}

require_once("$mosConfig_absolute_path/administrator/components/com_comment/library.comment.php");
require_once("$mosConfig_absolute_path/components/com_comment/joscomment/utils.php");
require_once("$mosConfig_absolute_path/administrator/components/com_comment/class.config.comment.php");
require_once($mainframe->getPath('admin_html'));


$config = new config();

$cid 		= JOSCGetArrayInts( 'cid' );

$fromcomponent 	= mosGetParam( $_REQUEST, 'fromcomponent', null );
$fromtable  	= mosGetParam( $_REQUEST, 'fromtable', null );

switch ($task) {
    
    case "new":
        editComment($option, 0);
        break;

    case "edit":
		$cid[0]	= ( $id ? $id : intval( $cid[0] ) );
        editComment($option, $cid[0]);
        break;

    case "save":
        saveComment($option);
        break;

    case "remove":
        removeComments($cid, $option);
        break;

    case "publish":
        publishComment($cid, 1, $option);
        break;

    case "unpublish":
        publishComment($cid, 0, $option);
        break;

    case "about":
        viewAbout(); /* library.comment.php */
        break;

    case "settings":
        $config->load();
        $config->execute($option);
        break;

    case "savesettings":
        $config->save($option);
        break;

    case "importcomment" :
    	HTML_comments::importPanel($option, $task, $fromtable, $fromcomponent);
    	break;
    	   	   	    	   	
/*  not used for parentid reason
    case "importexecuteSel" :
    	executeImport($cid, $option, $task, $fromtable, $fromcomponent);
    	break;
*/

    case "importexecuteAll" :
    	executeImport( -1, $option, $task, $fromtable, $fromcomponent);
    	break;

    case "convertlcharset" :
        $config->load();
    	convertlcharset($cid, $option, $config->_local_charset);
    	break;
    	
/*
    case "import":
        import($option);
        break;
*/
    default:
        viewComments($option, $task);
        break;
}

function convertlcharset($cid=null, $option, $local_charset) {

   global $database;

   if (!$local_charset) {
        echo "<script> alert('Local charset is empty ! check your setting'); window.history.go(-1);</script>\n";
        exit;
    }

   if (!is_array($cid) || $cid[0]<1) {
        $action = "convert to $local_charset";
        echo "<script> alert('Select at least an item to $action'); window.history.go(-1);</script>\n";
        exit;
    }
    $cids = implode(',', $cid);
    
    $message = "";
    
	/*
	 * #__comment
	 */
/*	$tabname 	= "#__comment_utf8";
	$table 		= $database->getTableFields(explode(",", $tabname)); // columns[table][fieldname]
    $database->setQuery("SHOW COLUMNS FROM $tabname");
    $columns = $database->loadObjectList();
*/ 
    $columns = josTableUtils::TableColumnsGet( '#__comment_utf8' );
    
    $advise = "<b>Tips:<br />if you encountered problems after conversion, you could use the backup table <i>comment_utf8</i> to retrieve your original datas by export/import."
			. "<br /> It contains ALL and ONLY the originals comments you have converted.</b><br /><br />"
			;
    if (!$columns) {
    	/*
    	 * backup table does not exist = create
    	 */
        $message .= "Table comment_utf8 backup creation:";
    	$database->SetQuery("CREATE TABLE IF NOT EXISTS `#__comment_utf8` SELECT * FROM `#__comment` WHERE id=0 ");
    	$result = $database->query();
    	if(!$result) {
	    	echo "Error: " . $database->stderr() . "<br /><br />";
	    	return;
    	} else {
	    	$message .= "OK.<br />".$advise;
    	}
 	} else
 	  	$message .= $advise;
 	

	/*
	 * convert lines
	 */
    $query  = "SELECT c.*, utf.id AS UTFID "
    		. "\n FROM `#__comment` AS c "
    		. "\n LEFT JOIN `#__comment_utf8` AS utf ON c.id = utf.id"
    		. "\n    WHERE c.id IN ($cids) "
    		;
    $database->SetQuery($query);
    $rows = $database->loadAssocList();
    if(!$rows) {
    	echo "Error: " . $database->stderr() . "<br /><br />";
    	return;
    } else {
        $err=0;
        $ok=0;
       	foreach($rows as $row) {
       	    if ($row['UTFID']) {
       	    	$message .= "Comment id=".$row['UTFID']." already converted.<br />";
       	    	continue;
       	    }
       	    /* first time: INSERT FIRST IN UTF8 table if not already done */
			$query = "INSERT IGNORE INTO `#__comment_utf8` SELECT * FROM `#__comment` WHERE id=".$row['id'];
			$database->SetQuery($query);
    		$result = $database->query();
    		if(!$result) {
    			$message .= "Error: " . $database->stderr() . "  Complete query $query<br />";
    			$err++;
    			continue;
    		}			
			$query = "INSERT IGNORE INTO `#__comment_utf8` SELECT * FROM `#__comment` WHERE id=".$row['id'];
			$database->SetQuery($query);
    		$result = $database->query();
    		if(!$result) {
    			$message .= "Error on comment ". $row['id'] ." : " . $database->stderr() . "  Complete query $query<br />";
    			$err++;
    			continue;
    		}
    		$local_charset = strtoupper($local_charset);
			$name 	 = myiconv_decode($row['name'], $local_charset );
			$title 	 = myiconv_decode($row['title'], $local_charset );    				
			$comment = myiconv_decode($row['comment'], $local_charset );
			if ( 	   ($row['name'] && !$name)
					|| ($row['title'] && !$title)
					|| ($row['comment'] && !$comment)
				) {
    			$message .= "Error on comment ". $row['id'] ." during iconv conversion. Please verify if $local_charset is supported by iconv OR try to convert manually this comment. <br />";
    			$err++;
    			continue;
       		}
       		$query 	= "UPDATE `#__comment` SET "
       				. "\n   name   ='".mysql_escape_string(strip_tags($name))."'"
       				. "\n , title  ='".mysql_escape_string(strip_tags($title))."'"
       				. "\n , comment='".mysql_escape_string(strip_tags($comment))."'"
					. "\n	WHERE id=".$row['id']." LIMIT 1 "
					;
		    $database->SetQuery($query);
    		$result = $database->query();
    		if(!$result) {
    			$message .= "Error on comment ". $row['id'] ." : " . $database->stderr() . " Complete query $query<br />";
    			$err++;
    		}
    		$ok++;
       	}
   		if ($err)
   			$message .= "$err error(s) !<br />";
   	  	$message .= "$ok line(s) updated.<br /> Process is finished..<br />";
   	  	
   	  	echo $message;
    }
}


function importMapping($option, $task, $fromtable='', $fromcomponent='') {

	global $mosConfig_dbprefix;
	
	$lists = array();
   	$sel_columns = false;

	$onchangecomponent =  mosGetParam( $_REQUEST, 'onchangecomponent', null );

	if ($onchangecomponent) {
		/*
	 	* from component = propose automatic columns selection
	 	*/
    	if ($fromcomponent && function_exists("getImport_".$fromcomponent)) {
			if ($result = call_user_func( "getImport_".$fromcomponent)) {
		   		$fromtable 		= $result['fromtable'];
				$sel_columns	= $result['sel_columns']; 	 /* ['sel_columns'][joscolumn] = component_column */
			}
    	}
	} else {
    	/*
	 	* get settings Parameters
	 	*/
		$joscomment = josTableUtils::TableColumnsGet( '#__comment' );
		foreach($joscomment as $col) {
	    	$param = mosGetParam( $_REQUEST, $col->Field, null );
	    	if ($param) {
	        	$sel_columns[$col->Field] = $param;
    	 	}
		}
	}
	
	/* 
	 * get all joomla tables 
	 */
	$tablelist = josTableUtils::getTableList();
	if ($fromtable && !in_array( $fromtable, $tablelist )) {
	    $fromtable = null;
	}
	$tablename = array();
	$columns = array();
	foreach ($tablelist as $tn) {
		// make sure we get the right tables based on prefix
		if (!preg_match( "/^".$mosConfig_dbprefix."/i", $tn )) {
			continue;
		}
		if ($tn==$fromtable) {
			/* 
	 		* get all fields of the selected table 
	 		*/
			$tablecolumns = josTableUtils::TableColumnsGet( $tn );
			foreach($tablecolumns as $col){
			    $columns[] = mosHTML::makeOption( $col->Field, $col->Field, 'Field', 'desc');
			}
		}
		$tablename[] = mosHTML::makeOption( $tn, $tn, 'tablename', 'desc');
	}
	 
	$selected = $fromcomponent;
	$components = setImport_ComponentList();
	array_unshift( $components, mosHTML::makeOption( '', '-- component --', 'component', 'desc' ) );
	$lists['fromcomponent'] = mosHTML::selectList( $components, 'fromcomponent', ' class="inputbox" onchange="document.location.href=\'index2.php?option='.$option.'&task='.$task.'&onchangecomponent=1&fromcomponent=\'+document.adminForm.fromcomponent.value;" ', 'component', 'desc', $selected );

	$selected = $fromtable;
	array_unshift( $tablename, mosHTML::makeOption( '', '-- Select a table name --', 'tablename', 'desc' ) );
	$lists['fromtable'] = mosHTML::selectList( $tablename, 'fromtable', ' class="inputbox" onchange="document.location.href=\'index2.php?option='.$option.'&task='.$task.'&fromtable=\'+document.adminForm.fromtable.value;" ', 'tablename', 'desc', $selected );

	$selected = '';
	array_unshift( $columns, mosHTML::makeOption( '', '-- column --', 'Field', 'desc') );
	$lists['columns'] = $columns; /* ->field, ->desc */
	$lists['sel_columns'] = $sel_columns; 	 /* ['sel_columns][joscolumn] = component_column */

	$lists['savequeries'] = mosHTML::yesnoRadioList('savequeries', 'class="inputbox"', false);
	
	HTML_comments::importMapping( $lists );
}

function previewImportComments($option, $task, $fromtable=null) {
    global $database, $mainframe, $mosConfig_absolute_path, $mosConfig_list_limit ;


	if (!$fromtable) {
		echo "<b>Select at least a table and apply.</b>";
		return;
	}

	$limit 		= intval( $mainframe->getUserStateFromRequest( "viewlistlimit", 'limit', $mosConfig_list_limit ) );
	$limitstart = intval( $mainframe->getUserStateFromRequest( "viewimp{$option}limitstart", 'limitstart', 0 ) );

    $search = $mainframe->getUserStateFromRequest("searchimp{$option}", 'search', '');
    $search = $database->getEscaped(trim(strtolower($search)));
    $where = array();
	
	/*
	 * construct SELECT [FIELDS] FROM [FROMTABLE]
	 */
	$columns = josTableUtils::TableColumnsGet( '#__comment' );

	/*
	 * construct SELECT clause from GetParam
	 */
	$fields = array();
	$idfound = false;
	$contentidfound = false;
	foreach($columns as $col) {
	    $param = mosGetParam( $_REQUEST, $col->Field, null );
	    if ($param) {
	        $fields[] = "f.$param AS $col->Field";
	        if ($col->Field == 'id') $idfound = true;
	        if ($col->Field == 'contentid') {
	        	$joincontentid = "f.$param"; /* for the left join content item */
	        	$contentidfound = true;
	        }
    		if ($search) {
        		$where[] = "LOWER(f.$param) LIKE '%$search%'";
    		}
    	 }
	}

	if (!$idfound) {
    	echo "<b>Id column is obligatory ! Please, select the column.</b>";
		return;
	}

	if (!$contentidfound) {
    	echo "<b>ContentId column is obligatory ! Please, select the column.</b>";
		return;
	}
		
	/*
	 * Queries
	 */
	
		
    $queryfrom			= $queryfromcount = "\n FROM $fromtable AS f";
    
    if ($joincontentid) {
		$queryfrom .= "\n LEFT JOIN #__content AS ct ON ct.id = $joincontentid";
		$fields[] 	= "ct.title AS ctitle"; /* for the left join content item */
	} 

    $queryselect  		= "SELECT " . implode(', ', $fields);
    $queryselectcount  	= "SELECT count(*)";
	$querywhere			= (count($where) ? ("\n WHERE ".implode(' OR ', $where)) : "");
	/*
	 * 
	 */
	$query = $queryselectcount . $queryfromcount . $querywhere;
    $database->setQuery($query);
    $total = $database->loadResult();
    echo $database->getErrorMsg();
    
	require_once( $GLOBALS['mosConfig_absolute_path'] . '/administrator/includes/pageNavigation.php' );
    $pageNav = new mosPageNav($total, $limitstart, $limit);
    	
    $query  = $queryselect
    		. $queryfrom   		
    		. $querywhere 
    		. "\n ORDER BY f.id " /* keep the creation order of fromtable */
    		;
    $database->SetQuery($query, $pageNav->limitstart,$pageNav->limit);
    $rows = $database->loadObjectList();

    $lists = array();
    $lists['noedit'] = true; /* do not set edit link function */
    $lists['noform'] = true; /* adminform already set */
    $lists['checkread'] = true; /* do not use checkbox */
    $lists['title'] = "Preview of what will be the result of import";
    
    HTML_comments::viewComments($option, $rows, $lists, $search, $pageNav, $task);
}

function executeImport($cid, $option, $task, $fromtable, $fromcomponent) {
    global $database, $mainframe, $mosConfig_absolute_path;
   
	if (!$fromtable) {
        echo "<script> alert('Select at least a table. Check your setting.'); window.history.go(-1);</script>\n";
        exit;
	}

   	if ($cid!=-1 && (!is_array($cid) || $cid[0]<1)) {
        $action = "import";
        echo "<script> alert('Select at least an item to $action'); window.history.go(-1);</script>\n";
        exit;
   	}    

	/*
	 * construct SELECT [FIELDS] FROM [FROMTABLE]
	 */
	$columns = josTableUtils::TableColumnsGet( '#__comment' );

	/*
	 * construct SELECT clause from GetParam
	 * 		$fromlist 	= from columns list (component)
	 * 		$tolist 	= to columns list  (joomlacomment)
	 */
	$tolist   = array();
	$fromlist = array();
	$idfound  = false;
	$contentidfound  = false;
	foreach($columns as $col) {
	    $param = mosGetParam( $_REQUEST, $col->Field, null );
	    if ($param) {
	        if ($col->Field == 'id') $idfound = true;
	        if ($col->Field == 'contentid') $contentidfound = true;
	        $tolist[] 	= "$col->Field";
	        $fromlist[] = "$param";
    	 }
	}

	if (!$fromlist) {
        echo "<script> alert('Select at least one field. Check your setting.'); window.history.go(-1);</script>\n";
        exit;
	}
	
	if (!$idfound) {
        echo "<script> alert('The Id field is obligatory. Check your setting.'); window.history.go(-1);</script>\n";
        exit;
	}
	
	if (!$contentidfound) {
        echo "<script> alert('The ContentId field is obligatory. Check your setting.'); window.history.go(-1);</script>\n";
        exit;
	}

	/*
	 * Queries
	 */

	$where = array();

 	$cids = "";
	if ($cid!=-1 && count($cid)) {
	    $cids =  implode(',', $cid);
		$where[] = " id IN ($cids) ";
	}
	
	$savequeries = mosGetParam( $_REQUEST, 'savequeries', false );
	$queries = ""; // will contain queries history
	
	$query 	= "INSERT INTO #__comment (".implode(',', $tolist).") "
			. "\n SELECT ".implode(',', $fromlist)." FROM $fromtable"
			. (count($where) ? ("\n WHERE ".implode('AND', $where)) : "")
			. " ORDER BY id"
			;
    $database->setQuery($query);    $queries .= "\n".$database->_sql.";";
    $result = $database->query();
	if ($result) {
		$query 	= "UPDATE #__comment SET parentid=-1 WHERE parentid = 0";
    	$database->setQuery($query);    $queries .= "\n".$database->_sql.";";
    	$result = $database->query();
	}
    if(!$result) {
		echo "Error: " . $database->stderr() . "<br /><br />";
		echo "Please copy the error message and contact the joomlacomment support";
    } else {
	   	$message = "Comments has been imported. Please verify the result below. ";
        if ($savequeries) {
        	if ($file = save_importQuery( $queries, $fromcomponent )) {
        		$message .= "---- sql queries has been saved in the $file.";
        	} else {
	        	$message .= "---- did not succeed to save sql queries in $file.";
    	    }
        }
	    mosRedirect("index2.php?option=$option", $message);
    }
        
}

function viewComments($option, $task)
{
    global $database, $mainframe, $mosConfig_absolute_path, $mosConfig_list_limit ;

	$limit 		= intval( $mainframe->getUserStateFromRequest( "viewlistlimit", 'limit', $mosConfig_list_limit ) );
	$limitstart = intval( $mainframe->getUserStateFromRequest( "viewcom{$option}limitstart", 'limitstart', 0 ) );

    $search = $mainframe->getUserStateFromRequest("search{$option}", 'search', '');
    $search = $database->getEscaped(trim(strtolower($search)));
    $where = array();
    if ($search) {
        $where[] = "LOWER(c.comment) LIKE '%$search%'";
        $where[] = "LOWER(ct.title) LIKE '%$search%'";
        $where[] = "LOWER(c.name) LIKE '%$search%'";
        $where[] = "LOWER(c.website) LIKE '%$search%'";
        $where[] = "LOWER(c.email) LIKE '%$search%'";
        $where[] = "LOWER(c.ip) LIKE '%$search%'";
        $where[] = "LOWER(c.ip) LIKE '%$search%'";
    }
    $database->setQuery("SELECT count(*) FROM #__comment AS c"
    		. "\n LEFT JOIN #__content  AS ct ON ct.id = c.contentid "
    		. (count($where) ? "\nWHERE " . implode(' OR ', $where) : ""));
    $total = $database->loadResult();
    echo $database->getErrorMsg();
    
	require_once( $GLOBALS['mosConfig_absolute_path'] . '/administrator/includes/pageNavigation.php' );
    $pageNav = new mosPageNav($total, $limitstart, $limit);

	$query = "SELECT c.*, u.email AS usermail, ct.title AS ctitle FROM #__comment AS c"
         . "\n LEFT JOIN #__users  AS u ON u.id = c.userid "
         . "\n LEFT JOIN #__content  AS ct ON ct.id = c.contentid "
         . (count($where) ? "\n WHERE " . implode(' OR ', $where) : "")
         . "\n ORDER BY c.id DESC"
         ;
    $database->setQuery( $query , $pageNav->limitstart, $pageNav->limit );
    $rows = $database->loadObjectList();
    if ($database->getErrorNum()) {
        echo $database->stderr();
        return false;
    }

    $lists = array();
    $lists['title'] = "List of joomlacomment Comments";
      
    HTML_comments::viewComments($option, $rows, $lists, $search, $pageNav, $task);
}

function publishComment($cid = null, $publish = 1, $option)
{
    global $database;
    if (!is_array($cid) || count($cid) < 1) {
        $action = $publish ? 'publish' : 'unpublish';
        echo "<script> alert('Select an item to $action'); window.history.go(-1);</script>\n";
        exit;
    }
    $cids = implode(',', $cid);
    $database->setQuery("UPDATE #__comment SET published='$publish' WHERE id IN ($cids)");
    if (!$database->query()) {
        echo "<script> alert('" . $database->getErrorMsg() . "'); window.history.go(-1); </script>\n";
        exit();
    }
	mosCache::cleanCache( 'com_content' );
	/*
	 * mail to notify :
	 *   the user of the approval
	 *   the users of those contentid of a new comment
	 */ 
	/****/
	 
    mosRedirect("index2.php?option=$option");
}

function editComment($option, $uid)
{
    global $database;

    $row = new josComment($database);
    $row->load($uid);

    $lists = array();

    $contentitem[] = mosHTML::makeOption('0', 'Select Content Item');
    $database->setQuery("SELECT id AS value, title AS text FROM #__content ORDER BY title");
    $contentitem = array_merge($contentitem, $database->loadObjectList());
    if (count($contentitem) < 1) {
        mosRedirect("index2.php?option=com_sections&scope=content", 'You must add content first.');
    }
    // build list of content
    $lists['content'] = $clist = mosHTML::selectList($contentitem, 'contentid', 'class="inputbox" size="1"', 'value', 'text', intval($row->contentid));
    
    // build list of users
    $lists['userid']	= mosAdminMenus::UserSelect( 'userid', $row->userid, 1, NULL, 'name', 0 );

    // build publish
    if ($uid) {
        $row->checkout($my->id);
    } else {
        $row->published = 0;
    }
    $lists['published'] = mosHTML::yesnoRadioList('published', 'class="inputbox"', $row->published);
 
    HTML_comments::editComment($option, $row, $lists);
}

function saveComment($option)
{
    global $database;
    $row = new josComment($database);
    if (!$row->bind($_POST)) {
        echo "<script> alert('" . $row->getError() . "'); window.history.go(-1); </script>\n";
        exit();
    }
    $row->date = date("Y-m-d H:i:s");
    $row->ip = getenv('REMOTE_ADDR');
    if (!$row->store()) {
        echo "<script> alert('" . $row->getError() . "'); window.history.go(-1); </script>\n";
        exit();
    }
    $row->updateOrder("contentid='$row->contentid'");
	mosCache::cleanCache( 'com_content' );
    mosRedirect("index2.php?option=$option");
}

function removeComments($cid, $option)
{
    global $database;
    if (count($cid)) {
        $cids = implode(',', $cid);
        $database->setQuery("DELETE FROM #__comment WHERE id IN ($cids)");
        if (!$database->query()) {
            echo "<script> alert('" . $database->getErrorMsg() . "'); window.history.go(-1); </script>\n";
        }
    }
	mosCache::cleanCache( 'com_content' );
    mosRedirect("index2.php?option=$option");
}

function setImport_ComponentList() {
	
	$result = array();
	/*
	 * important: the fromcomponent value will be used as function name
	 */
	$fromcomponent = 'mXcomment';
	if (function_exists("getImport_".$fromcomponent))
		$result[] = mosHTML::makeOption( $fromcomponent, $fromcomponent, 'component', 'desc' );
	$fromcomponent = 'AkoComment';
	if (function_exists("getImport_".$fromcomponent))
		$result[] = mosHTML::makeOption( $fromcomponent, $fromcomponent, 'component', 'desc' );
	$fromcomponent = 'JReaction';
	if (function_exists("getImport_".$fromcomponent))
		$result[] = mosHTML::makeOption( $fromcomponent, $fromcomponent, 'component', 'desc' );
		
	return($result);
}

function save_importQuery( $query, $component='', $option='') {

        global $mosConfig_absolute_path;

        $File = "media/joscomment_importquery_$component.sql";

        if ($fp = fopen( $mosConfig_absolute_path."/".$File , "w")) {
            fputs($fp, $query, strlen($query));
            fclose ($fp);
        } else {
            if ($option) {
                  mosRedirect("index2.php?option=$option", 'File $File
creation error!');
                  break;
            } else return false;
        }

        if ($option) {
            mosRedirect("index2.php?option=$option", 'Query saved');
        } else return $File;
}

/* ---------------------------------------------
 * --- P R E - D E F I N E D   I M P O R T S ---
 */

function getImport_mXcomment() {
    global $mosConfig_dbprefix;
    
	$result['fromtable'] = $mosConfig_dbprefix.'mxc_comments';
	 /* ['sel_columns'][joscolumn] = component_column */
	$result['sel_columns']['id'] 		= 'id';
	$result['sel_columns']['contentid'] = 'contentid';
	$result['sel_columns']['date'] 		= 'date';
	$result['sel_columns']['name'] 		= 'name';
	$result['sel_columns']['userid'] 	= 'iduser';
	$result['sel_columns']['ip'] 		= 'ip';
	$result['sel_columns']['email']		= 'email';
	$result['sel_columns']['notify']	= 'subscribe';
	$result['sel_columns']['website']	= 'web';
	$result['sel_columns']['title']		= 'title';
	$result['sel_columns']['comment']	= 'comment';
	$result['sel_columns']['published']	= 'published';
	$result['sel_columns']['voting_yes'] = 'rating'; /* better than nothing */
	$result['sel_columns']['parentid']	= 'parentid';

	return( $result );
}

function getImport_AkoComment() {
    global $mosConfig_dbprefix;
    
	$result['fromtable'] = $mosConfig_dbprefix.'akocomment';
	 /* ['sel_columns'][joscolumn] = component_column */
	$result['sel_columns']['id'] 		= 'id';
	$result['sel_columns']['contentid'] = 'contentid';
	$result['sel_columns']['date'] 		= 'date';
	$result['sel_columns']['name'] 		= 'name';
	$result['sel_columns']['userid'] 	= 'iduser';
	$result['sel_columns']['ip'] 		= 'ip';
	$result['sel_columns']['email']		= 'email';
	$result['sel_columns']['notify']	= 'subscribe';
	$result['sel_columns']['website']	= 'web';
	$result['sel_columns']['title']		= 'title';
	$result['sel_columns']['comment']	= 'comment';
	$result['sel_columns']['published']	= 'published';
//	$result['sel_columns']['voting_yes'] = 'rating'; 
	$result['sel_columns']['parentid']	= 'parentid';

	return( $result );
}

function getImport_JReaction() {
    global $mosConfig_dbprefix;
    
	$result['fromtable'] = $mosConfig_dbprefix.'jreactions';
	 /* ['sel_columns'][joscolumn] = component_column */
	$result['sel_columns']['id'] 		= 'id';
	$result['sel_columns']['contentid'] = 'contentid';
	$result['sel_columns']['date'] 		= 'date';
	$result['sel_columns']['name'] 		= 'name';
	$result['sel_columns']['userid'] 	= 'userid';
	$result['sel_columns']['ip'] 		= 'ip';
	$result['sel_columns']['email']		= 'email';
	//$result['sel_columns']['notify']	= 'subscribe';
	$result['sel_columns']['website']	= 'website';
	$result['sel_columns']['title']		= 'title';
	$result['sel_columns']['comment']	= 'comments';
	$result['sel_columns']['published']	= 'published';
	$result['sel_columns']['voting_yes'] = 'rank'; /* better than nothing */ 
	//$result['sel_columns']['parentid']	= 'parentid';

	return( $result );
}

?>